package cn.wolfcode.jedis;

import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class JedisTestSet {
    @Test
    public void test(){
        // 1:创建Jedis连接池
        JedisPool pool = new JedisPool("localhost", 6379);
        // 2:从连接池中获取Jedis对象
        Jedis jedis = pool.getResource();
        /*设置密码
	    jedis.auth("");*/
        // 3:TODO
        //set类型

        /*往set集合中添加元素
        列出set集合中的元素
        jedis.sadd("set1","1","2","3","4");
        System.out.println(jedis.smembers("set1"));*/

        /*随机弹出集合中的元素
        System.out.println(jedis.spop("set1", 2));*/

        /*jedis.sadd("set1","1","2","3","4");
        jedis.sadd("set2","5","6","3","4");*/

        /*返回key1中特有元素(差集)
        System.out.println(jedis.sdiff("set1", "set2"));
        返回两个set集合的交集
        System.out.println(jedis.sinter("set1", "set2"));
        返回两个set集合的并集
        System.out.println(jedis.sunion("set1", "set2"));*/
        // 4:关闭资源
        jedis.close();
        pool.destroy();
    }
}
